<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="/static/common/taglib.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title>日常巡检统计</title>
    <%@include file="../../public/commonCss.jsp" %>
    <%@include file="../../public/commonJs.jsp" %>
</head>
<body ms-controller="main" class="ms-controller">
<div id="wrapper">
    <div class="boxmain whiteBox lrbox">
        <div class="lrboxleft borderR">
            <div class="from-header borderB ">
                <span class="font14">角色菜单</span>
                <span class="classifyEdit fr">
				</span>
            </div>
            <div class="from-body withheader contentbox8">
                <ul id="treeDemo" class="ztree" style="width:100%;height: 100%; overflow: auto;"></ul>
            </div>
        </div>
        <div class="lrboxmain borderL">
            <div class="from-header borderB contentbox">
                <div>
                    <button class="button-noborder" id="sidebarToggle" type="button"
                            style="margin-left:0px;margin-right:5px;">
                        <i class="fa fa-arrows-alt fa-lg"></i>
                    </button>
                    <span class="dividers"></span>
                    <span class="font14">所属分类:</span><a id="category"><span style="">角色菜单</span></a>
                </div>
            </div>
            <div class="from-body withheader" style=" overflow: auto;">
                <iframe id="iFrame"></iframe>
            </div>
        </div>
    </div>
    <!-- whitebox -->
</div>
<script type="text/javascript">
    var vm;
    var zTreeObj;
    avalon.ready(function () {
        vm = avalon.define({
            $id: "main",
            treeDatas: [],//菜单数据
            selectNode: {}
        })
        loadTreeData();
        avalon.scan();
    });
    //搜索
    function searchData() {
        loadTreeData();
    }
    //加载菜单数据
    function loadTreeData() {
        $.ajax({
            type: 'post',
            url: '${ctx}/roleMenuController/selectAllRole.action',
            data: '',
            dataType: "json",
            timeout: 10000,
            success: function (data) {
                if (data.code == 0) {
                    vm.treeDatas = data.datas;
                    initZTree();
                } else if (data.code == -1) {
                    top.showErrorMsg("数据加载失败");
                }
            }
        });
    }

    //初始化树
    function initZTree() {
        var setting = {
            data: {
                simpleData: {
                    enable: true, //是否启用简单数据类型
                    idKey: "id",
                    pIdKey: "pid",
                    rootPId: 0
                }
            },
            callback: { //回调
                onClick: nodeOnClick
            }
        };
        zTreeObj = $.fn.zTree.init($("#treeDemo"), setting, vm.$model.treeDatas);
        zTreeObj.expandAll(true);
    }
    function selectNodeById(nodeId) {
        var node = zTreeObj.getNodeByParam("id", nodeId, null);
        console.log(node)
        if (node != null) {
            vm.selectNode = node;
            zTreeObj.selectNode(node);
        }
    }
    //点击节点的回调
    function nodeOnClick(event, treeId, treeNode) {
        if (treeNode.id == 'root') {
            return;
        }
        var url = "${ctx}/roleMenuController/toRoleMenuList.action?roleType=" + treeNode.roleType;
        setIframeSrc(url);
    }

    //设置iframe url地址
    function setIframeSrc(url) {
        $("#iFrame").attr("src", url);
    }
</script>
</body>
</html>